<?php

namespace App\Http\Controllers;

use Qiniu\Auth as QiniuAuth;
use Illuminate\Http\Request;

class QiniuController extends Controller
{

    public function token(Request $request)
    {
        $qiniu_auth = new QiniuAuth(env('QINIU_ACCESS_KEY', ''), env('QINIU_SECRET_KEY', ''));
        $policy = array(
            "returnBody" => '{"key": $(key), "hash": $(etag), "w": $(imageInfo.width), "h": $(imageInfo.height)}'
        );


        $qiniu_token = $qiniu_auth->uploadToken(env('QINIU_BUCKET_NAME', ''), null, 3600, $policy);

        $result = [
            'uptoken' => $qiniu_token,
        ];
        return response($result);
    }


}
